#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
    pid_t id = fork();
    if (id == 0)
    {
        int cnt = 5;
        while (cnt--)
        {
            printf("i am child process\n");
            sleep(1);
        }
        exit(11);
    }
    else 
    {
        while (1)
        {
            int statuc = 0;
            int ret = waitpid(id, &statuc, WNOHANG);
            if (ret == 0)
            {
                printf("child not exit, pleace do other things\n");
            }
            else if (ret > 0)
            {
                printf("child exit, exit code: %d, exit single: %d\n", statuc >> 8, statuc & 0x7F);
                break;
            }
            else 
            {
                printf("child process wrong\n");
            }
            sleep(1);
        }
    }

    return 0;
}
